class Solution {
public:
    /**
     * @param a: An integer
     * @param b: An integer
     * @return: An integer
     */
    int bitSwapRequired(int a, int b) {
        // write your code here
        return bitCount(a ^ b);
    }

    int bitCount(int a) {
        int count = 0;
        // Can be more performance than the following code.
        for (int i = 1; i <= 32; i++) {
            if (a & 1 << i) {
                count++;
            }
        }

        return count;
    }
};

class Solution1 {
public:
    /**
     * @param a: An integer
     * @param b: An integer
     * @return: An integer
     */
    int bitSwapRequired(int a, int b) {
        // write your code here
        return bitCount(a ^ b);
    }

    int bitCount(int a) {
        a = (a & 0x55555555) + ((a >> 1) & 0x55555555);
        a = (a & 0x33333333) + ((a >> 2) & 0x33333333);
        a = (a & 0x0F0F0F0F) + ((a >> 4) & 0x0F0F0F0F);
        a = (a & 0x00FF00FF) + ((a >> 8) & 0x00FF00FF);
        a = (a & 0x0000FFFF) + ((a >> 16) & 0x0000FFFF);
        return a;
    }
};
